<?php

namespace app\models\db;

use Yii;

/**
 * This is the model class for table "t_user".
 *
 * @property string $id
 * @property string $mini_programes
 * @property string $name
 * @property string $phone
 * @property string $xw_openid
 * @property string $zfb_openid
 * @property string $header_url
 * @property string $password
 * @property string $integral
 * @property string $create_datetime
 * @property string $remark
 * @property integer $is_enable
 * @property string $token
 *
 * @property Address[] $tAddresses
 * @property Cart[] $tCarts
 * @property Favourite[] $tFavourites
 * @property Order[] $tOrders
 * @property MiniPrograms $miniProgrames
 */
class TUser extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_user';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['integral'], 'number'],
            [['create_datetime'], 'safe'],
            [['is_enable'], 'integer'],
            [['id', 'mini_programes'], 'string', 'max' => 36],
            [['name', 'xw_openid', 'zfb_openid', 'header_url', 'password', 'remark', 'token'], 'string', 'max' => 255],
            [['phone'], 'string', 'max' => 30],
            [['xw_openid'], 'unique'],
            [['zfb_openid'], 'unique'],
            [['mini_programes'], 'exist', 'skipOnError' => true, 'targetClass' => MiniPrograms::className(), 'targetAttribute' => ['mini_programes' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'mini_programes' => 'Mini Programes',
            'name' => 'Name',
            'phone' => 'Phone',
            'xw_openid' => 'Xw Openid',
            'zfb_openid' => 'Zfb Openid',
            'header_url' => 'Header Url',
            'password' => 'Password',
            'integral' => 'Integral',
            'create_datetime' => 'Create Datetime',
            'remark' => 'Remark',
            'is_enable' => 'Is Enable',
            'token' => 'Token',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTAddresses()
    {
        return $this->hasMany(Address::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTCarts()
    {
        return $this->hasMany(Cart::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTFavourites()
    {
        return $this->hasMany(Favourite::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getTOrders()
    {
        return $this->hasMany(Order::className(), ['user_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMiniProgrames()
    {
        return $this->hasOne(MiniPrograms::className(), ['id' => 'mini_programes']);
    }
}
